<?php
$loader->requireOnce('ordo/TicketItem.class.php');
$loader->requireOnce('ordo/PackageItem.class.php');

class TicketRender {

	public static function renderHTMLTest($ticketTestId) {
		$item = Celini::newORDO('TestItem', $ticketTestId);
		$testId = $item->get('test_id');

		$testOrdo = Celini::newORDO('Test', $testId);
		$testName = $testOrdo->getLocalizedText('name');

		$asso = Celini::newORDO('TestItemAssoService');
		$res = $asso->listTestService($ticketTestId);
		return self::buildHTMLTest($testName, $res);
	}

	public static function renderHTMLCompositeService($ticketItemId) {
		$item = Celini::newORDO('TicketItem', $ticketItemId);
		$compositeId = $item->get('item_id');

		$compositeOrdo = Celini::newORDO('CompositeService', $compositeId);
		$compositeName = $compositeOrdo->getLocalizedText('name');

		$compositeItem = Celini::newORDO('CompositeServiceItem');
		$compositeAsso = Celini::newORDO('CompositeServiceAsso');
		$allServices = $compositeAsso->listCompositeService($compositeId);
		for ($i = 0; $i < sizeof($allServices); $i++){
			// check for selected optional service
			if ($allServices[$i]['optional'] == 'no'){
				$allServices[$i]['selected'] = 'yes';
			} else {
				$isSelected = $compositeItem->isItem($ticketItemId, $allServices[$i]['service_id']);
				if ($isSelected != false){
					$allServices[$i]['selected'] = 'yes';
				} else {
					$allServices[$i]['selected'] = 'no';
				}
			}
		}
		return self::buildHTMLCompositeService($compositeId, $allServices);
	}

	public static function renderPackageTest($packageTestId) {
		$item = Celini::newORDO('PackageTestItem', $packageTestId);
		$testId = $item->get('test_id');

		$testOrdo = Celini::newORDO('Test', $testId);
		$testName = $testOrdo->getLocalizedText('name');

		$asso = Celini::newORDO('PackageTestAssoService');
		$res = $asso->listTestService($packageTestId);
		return self::buildHTMLTest($testName, $res);
	}

	public static function renderPackageItem($packageItemId, $fields) {
		$item = Celini::newORDO('PackageItem', $packageItemId);
		$type = $item->get('item_type');

		$result = false;
		if ($type == PackageItem::SERVICE_TYPE) {
			$result = $item->getServiceItem($packageItemId);
		} else if ($type == PackageItem::TEST_TYPE) {
			$result = $item->getTestItem($packageItemId);
		}

		if (!$result) {
			return "";
		}
		return self::buildPackageItem($result, $fields, true);
	}

	public static function renderPackageItemWithoutLink($packageItemId, $fields) {
		$item = Celini::newORDO('PackageItem', $packageItemId);
		$type = $item->get('item_type');

		$result = false;
		if ($type == PackageItem::SERVICE_TYPE) {
			$result = $item->getServiceItem($packageItemId);
		} else if ($type == PackageItem::TEST_TYPE) {
			$result = $item->getTestItem($packageItemId);
		}

		if (!$result) {
			return "";
		}
		return self::buildPackageItem($result, $fields, false);
	}

	public static function renderHTMLServiceItem($ticketItemId, $fields = array(), $userRole=false, $viewClosed = false) {
		$item = Celini::newORDO('TicketItem');
		$result = $item->getServiceItem($ticketItemId);

		if (!$result) {
			return "";
		}
		return self::buildHTMLServiceItem($result, $fields, $userRole, $viewClosed);
	}

	public static function renderHTMLLabItem($ticketItemId, $fields = array(), $userRole=false, $viewClosed = false) {
		$item = Celini::newORDO('TicketItem');
		$result = $item->getLabItem($ticketItemId);
		if (!$result) {
			return "";
		}
		return self::buildHTMLLabItem($result, $fields, $userRole, $viewClosed);
	}

	public static function renderHTMLRadItem($ticketItemId, $fields = array(), $userRole=false, $viewClosed = false) {
        // Get ticket item info
        $result   =   ORDataObject::factory('TicketItem')->getRadItem($ticketItemId);
        if (!$result) {
            return "";
        }
        return self::buildHTMLRadItem($result, $fields, $userRole, $viewClosed);
	}
	public static function renderHTMLCompositeItem($ticketItemId, $fields = array(), $userRole=false, $viewClosed = false) {
		$item = Celini::newORDO('TicketItem');
		$result = $item->getCompositeItem($ticketItemId);
		if (!$result) {
			return "";
		}
		// Get the status of this ticket
		$ticketItem = Celini::newORDO('TicketItem', $ticketItemId);
		$ticketId = $ticketItem->get('ticket_id');
		$ticket = Celini::newORDO('Ticket', $ticketId);
		$status = $ticket->get('status');
		return self::buildHTMLCompositeItem($result, $fields, $status, $userRole, $viewClosed);
	}

	public static function renderHTMLClosedServiceItem($ticketItemId, $fields = array()) {
		$item = Celini::newORDO('TicketItem');
		$result = $item->getServiceItem($ticketItemId);
		if (!$result) {
			return "";
		}
		return self::buildHTMLServiceItem($result, $fields, '', true);
	}

	public static function renderHTMLClosedTestItem($ticketItemId, $fields = array()) {
		$item = Celini::newORDO('TicketItem');
		$result = $item->getTestItem($ticketItemId);
		if (!$result) {
			return "";
		}
		return self::buildHTMLTestItem($result, $fields, '', true);
	}

	private static function buildOrdering($ticketId, $ticketItemId) {

		$ticket = Celini::newORDO('Ticket');

		$itemId = $ticket->getFirstTicketItem($ticketId, TicketItem::IN_PROGRESS);
		if ($itemId == $ticketItemId) {
			return "<td align=\"right\">
						<a class=\"down_item\" href=\"javascript:turnDown($ticketItemId);\" title=\"".L10nHelper::_("Down")."\"><img src=\"../images/small_down.png\" /></a>
					</td>";
		}

		$firstOpen = $ticket->getFirstTicketItem($ticketId, TicketItem::OPEN);
		if ($itemId === false && $firstOpen == $ticketItemId) {
			 return "<td align=\"right\">
						<a class=\"down_item\" href=\"javascript:turnDown($ticketItemId);\" title=\"".L10nHelper::_("Down")."\"><img src=\"../images/small_down.png\" /></a>
					</td>";
		}

		$res = $ticket->isLastOpenItem($ticketItemId);
		if ($res) {
			return "<td>
						<a class=\"up_item\" href=\"javascript:turnUp($ticketItemId);\" title=\"".L10nHelper::_("Up")."\"><img src=\"../images/small_up.png\" /></a>
					</td>";
		}

		if (Celini::newORDO('TicketItem', $ticketItemId)->get('status') == TicketItem::OPEN) {
			return "<td>
						<a class=\"up_item\" href=\"javascript:turnUp($ticketItemId);\" title=\"".L10nHelper::_("Up")."\"><img src=\"../images/small_up.png\" /></a>
						<a class=\"down_item\" href=\"javascript:turnDown($ticketItemId);\" title=\"".L10nHelper::_("Down")."\"><img src=\"../images/small_down.png\" /></a>
					</td>";
		}
		return "<td>&nbsp;</td>";

	}

	private static function buildHTMLLabItem($data, $fields, $userRole, $viewClosed) {
		$order = $data['item_order'];
		$id = $data['ticket_item_id'];

		$renderAll = (sizeof($fields) == 0) ? TRUE : FALSE;

		$result = "<tr id=\"$id\" >";
		if ($renderAll || in_array('ordering', $fields)) {
			$result .= self::buildOrdering($data['ticket_id'], $data['ticket_item_id']);
		}
		$result .= "<td>
						<span class=\"order\">" . $data['item_order'] . "</span>
					</td>";

		if ($renderAll || in_array('service_name', $fields)) {
			$result .= "<td><a href=\"javascript:labAssignmentDetail('" .
			 $data['ticket_id'] . "','" . $data['item_id'] . "');\" title=\"".L10nHelper::_("Detail")."\">" . $data['service_name'] . "</a></td>";
		}
		if ($renderAll || in_array('room_name', $fields)) {
			$result .= "<td>" . $data['room_name'] . "</td>";
		}

		if ($renderAll || in_array('patient_price', $fields)) {
			$result .= "<td>" . L10nHelper::renderCurrency($data['patient_price']) . "</td>";
		}

		// 	Currently discount on TEST is not allowed
		// It always is zero
		if ($renderAll || in_array('discount', $fields)) {
			$result .= "<td>" . L10nHelper::renderCurrency($data['discount']) . "</td>";
			$result .= "<td>" . L10nHelper::renderCurrency($data['patient_price'] - $data['discount']) . "</td>";
		}

		if ($renderAll || in_array('payment_type', $fields)) {
			$temp = Utils::getEnumTextByKey(EnumerationConstant::PAYMENT_TYPE, $data['payment_type']);
			$result .= "<td>" . $temp . "</td>";
		}
		if ($renderAll || in_array('pre_paid', $fields)) {
			$result .= "<td><span class=\"strong\" id=\"$id\">" . $data['pre_paid'] ."</span></td>";
		}
		if ($renderAll || in_array('status', $fields)) {
			$result .= "<td>" . self::getTicketItemStatus($data['status']) . "</td>";
		}
		if ($renderAll || in_array('cancel_button', $fields)) {

			$res = self::determineClassCSS($data['status']);
			$textClass = $res['textClass'];
			$delClass = $res['delClass'];

			// TRUNG NGUYEN - 04/02/2009
			// Allow to delete service that had advance payment
			$result .= "<td>"
					. "<a class=\"$delClass\" href=\"javascript:deleteLabTicketItem('" .
             $id . "','" . $data['item_id'] . "');\"><img src=\"../images/remove_small.png\"</a> </td>";

			if ($userRole == 'doctor') {
				if ($data['status'] == TicketItem::WAITING) {
					$result .= "<td><a class=\"$textClass\" href=\"javascript:continueEncounter($id);\">".L10nHelper::_("Continue_1")."</a></td>";
				} else if ($data['status'] == TicketItem::IN_PROGRESS){
					$result .= "<td><a class=\"$textClass\" href=\"javascript:waitForParaClinicService($id);\">".L10nHelper::_("Test")."</a></td>";
				} else {
					$result .= "<td>&nbsp;</td>";
				}
				$result .= "<td><a class=\"$textClass\" href=\"javascript:completeTicketItem($id);\">".L10nHelper::_("Finish")."</a></td>";
			}

		}
		$result .= "</tr>";
		return $result;
	}

    private static function buildHTMLRadItem($data, $fields, $userRole, $viewClosed) {
        $order = $data['item_order'];
        $id = $data['ticket_item_id'];

        $renderAll = (sizeof($fields) == 0) ? TRUE : FALSE;

        $result = "<tr id=\"$id\" >";
        if ($renderAll || in_array('ordering', $fields)) {
            $result .= self::buildOrdering($data['ticket_id'], $data['ticket_item_id']);
        }
        $result .= "<td>
                        <span class=\"order\">" . $data['item_order'] . "</span>
                    </td>";

        if ($renderAll || in_array('service_name', $fields)) {
            $result .= "<td><a href=\"javascript:radAssignmentDetail('" .
             $data['item_id'] . "','" . $data['paraclinic_type'] . "');\" title=\"".L10nHelper::_("View details")."\">" . $data['service_name'] . "</a></td>";
        }
        if ($renderAll || in_array('room_name', $fields)) {
            $result .= "<td>" . $data['room_name'] . "</td>";
        }

        if ($renderAll || in_array('patient_price', $fields)) {
            $result .= "<td>" . L10nHelper::renderCurrency($data['patient_price']) . "</td>";
        }

        //  Discount calculating on Radiology services is temporaryly not available
        // It always is zero
        if ($renderAll || in_array('discount', $fields)) {
            $result .= "<td>" . L10nHelper::renderCurrency($data['discount']) . "</td>";
            $result .= "<td>" . L10nHelper::renderCurrency($data['patient_price'] - $data['discount']) . "</td>";
        }

        if ($renderAll || in_array('payment_type', $fields)) {
            $temp = Utils::getEnumTextByKey(EnumerationConstant::PAYMENT_TYPE, $data['payment_type']);
            $result .= "<td>" . $temp . "</td>";
        }
        if ($renderAll || in_array('pre_paid', $fields)) {
            $result .= "<td><span class=\"strong\" id=\"$id\">" . $data['pre_paid'] ."</span></td>";
        }
        if ($renderAll || in_array('status', $fields)) {
            $result .= "<td>" . self::getTicketItemStatus($data['status']) . "</td>";
        }
        if ($renderAll || in_array('cancel_button', $fields)) {

            $res = self::determineClassCSS($data['status']);
            $textClass = $res['textClass'];
            $delClass = $res['delClass'];

            // TRUNG NGUYEN - 04/02/2009
            // Allow to delete service that had advance payment
            $result .= "<td>"
                    . "<a class=\"$delClass\" href=\"javascript:deleteRadTicketItem('" .
             $id . "','" . $data['item_id'] . "');\"><img src=\"../images/remove_small.png\" title=\"". L10nHelper::_('Delete') ."\"/></a> </td>";

            if ($userRole == 'doctor') {
                if ($data['status'] == TicketItem::WAITING) {
                    $result .= "<td><a class=\"$textClass\" href=\"javascript:continueEncounter($id);\">".L10nHelper::_("Continue_1")."</a></td>";
                } else if ($data['status'] == TicketItem::IN_PROGRESS){
                    $result .= "<td><a class=\"$textClass\" href=\"javascript:waitForParaClinicService($id);\">".L10nHelper::_("Paraclinique")."</a></td>";
                } else {
                    $result .= "<td>&nbsp;</td>";
                }
                $result .= "<td><a class=\"$textClass\" href=\"javascript:completeTicketItem($id);\">".L10nHelper::_("Finish")."</a></td>";
            }

        }
        $result .= "</tr>";
        return $result;
    }

	private static function buildHTMLCompositeItem($data, $fields, $status, $userRole, $viewClosed) {
		$order = $data['item_order'];
		$id = $data['ticket_item_id'];

		$renderAll = (sizeof($fields) == 0) ? TRUE : FALSE;

		$result = "<tr id=\"$id\" >";
		if ($renderAll || in_array('ordering', $fields)) {
			$result .= self::buildOrdering($data['ticket_id'], $data['ticket_item_id']);
		}
		$result .= "<td>
						<span class=\"order\">" . $data['item_order'] . "</span>
					</td>";

		if ($renderAll || in_array('service_name', $fields)) {
			if ($status == Ticket::CLOSED_STATUS){
				$result .= "<td><a href=\"javascript:compositeServiceDetail($id, 'closed');\" title=\"".L10nHelper::_("Service group detail")."\">" . $data['service_name'] . "</a></td>";
			} else {
				$result .= "<td><a href=\"javascript:compositeServiceDetail($id, 'open');\" title=\"".L10nHelper::_("Service group detail")."\">" . $data['service_name'] . "</a></td>";
			}

		}
		if ($renderAll || in_array('room_name', $fields)) {
			$result .= "<td>" . $data['room_name'] . "</td>";
		}

		if ($renderAll || in_array('patient_price', $fields)) {
			$result .= "<td>" . L10nHelper::renderCurrency($data['patient_price']) . "</td>";
		}

		// 	Currently discount on TEST is not allowed
		// It always is zero
		if ($renderAll || in_array('discount', $fields)) {
			$result .= "<td>" . L10nHelper::renderCurrency($data['discount']) . "</td>";
			$result .= "<td>" . L10nHelper::renderCurrency($data['patient_price'] - $data['discount']) . "</td>";
		}

		if ($renderAll || in_array('payment_type', $fields)) {
			$temp = '';
			if ($data['payment_type'] == Service::AFTER) {
				$temp = L10nHelper::_("Postpaid");
			} else if ($data['payment_type'] == Service::BEFORE) {
				$temp = L10nHelper::_("Prepaid");
			}
			$result .= "<td>" . $temp . "</td>";
		}
		if ($renderAll || in_array('pre_paid', $fields)) {
			$result .= "<td><span class=\"strong\" id=\"$id\">" . $data['pre_paid'] ."</span></td>";
		}
		if ($renderAll || in_array('status', $fields)) {
			$result .= "<td>" . self::getTicketItemStatus($data['status']) . "</td>";
		}
		if ($renderAll || in_array('cancel_button', $fields)) {

			$res = self::determineClassCSS($data['status']);
			$textClass = $res['textClass'];
			$delClass = $res['delClass'];

			$pc = Celini::newORDO('PaymentCollection');
			if ($pc->isCollected($id)) {
				$result .= "<td>".L10nHelper::_("Prepayment")."</td>";
			} else {
				$result .= "<td>"
					. "<a class=\"$delClass\" href=\"javascript:deleteTicketItem($id);\"><img src=\"../images/remove_small.png\"</a> </td>";
			}
			if ($userRole == 'doctor') {
				if ($data['status'] == TicketItem::WAITING) {
					$result .= "<td><a class=\"$textClass\" href=\"javascript:continueEncounter($id);\">".L10nHelper::_("Continue_1")."</a></td>";
				} else if ($data['status'] == TicketItem::IN_PROGRESS){
					$result .= "<td><a class=\"$textClass\" href=\"javascript:waitForParaClinicService($id);\">".L10nHelper::_("Test")."</a></td>";
				} else {
					$result .= "<td>&nbsp;</td>";
				}
				$result .= "<td><a class=\"$textClass\" href=\"javascript:completeTicketItem($id);\">".L10nHelper::_("Finish")."</a></td>";
			}

		}
		$result .= "</tr>";
		return $result;
	}

	private static function buildHTMLServiceItem($data, $fields, $userRole, $viewClosed) {
		$order = $data['item_order'];
		$id = $data['ticket_item_id'];

		$renderAll = (sizeof($fields) == 0) ? TRUE : FALSE;

		$result = "<tr id=\"$id\" class='contextMenu'>";
		if ($renderAll || in_array('ordering', $fields)) {
			$result .= self::buildOrdering($data['ticket_id'], $data['ticket_item_id']);
		}
		$result .= "<td><span class=\"order\">" . $data['item_order'] . "</span></td>";
		if ($renderAll || in_array('service_name', $fields)) {
			$result .= "<td>" . $data['service_name'] . "</td>";
		}
		if ($renderAll || in_array('room_name', $fields)) {
			$result .= "<td>" . $data['room_name'] . "</td>";
		}
		if ($renderAll || in_array('patient_price', $fields)) {
			$result .= "<td>" . L10nHelper::renderCurrency($data['patient_price']) . "</td>";
		}

		if ($renderAll || in_array('discount', $fields)) {
			$result .= "<td>" . L10nHelper::renderCurrency($data['discount']) . "</td>";
			$result .= "<td>" . L10nHelper::renderCurrency($data['patient_price'] - $data['discount']) . "</td>";
		}

		if ($renderAll || in_array('payment_type', $fields)) {
			$temp = '';
			if ($data['payment_type'] == Service::AFTER) {
				$temp = L10nHelper::_("Postpaid");
			} else if ($data['payment_type'] == Service::BEFORE) {
				$temp = L10nHelper::_("Prepaid");
			}
			$result .= "<td>" . $temp . "</td>";
		}
		if ($renderAll || in_array('pre_paid', $fields)) {
			$result .= "<td><span class=\"strong\" id=\"$id\">" . L10nHelper::renderCurrency($data['pre_paid']) ."</span></td>";
		}
		if ($renderAll || in_array('status', $fields)) {
			$result .= "<td>" . self::getTicketItemStatus($data['status']) . "</td>";
		}
		if ($renderAll || in_array('cancel_button', $fields)) {

			$res = self::determineClassCSS($data['status']);
			$textClass = $res['textClass'];
			$delClass = $res['delClass'];

			// TRUNG NGUYEN - 04/02/2009
			// Allow to delete service that had advance payment
			$result .= "<td>"
				. "<a class=\"$delClass\" href=\"javascript:deleteTicketItem($id);\"><img src=\"../images/remove_small.png\"</a> </td>";

			if ($userRole == 'doctor') {
				if ($data['status'] == TicketItem::WAITING) {
					$result .= "<td><a class=\"$textClass\" href=\"javascript:continueEncounter($id);\">".L10nHelper::_("Continue_1")."</a></td>";
				} else if ($data['status'] == TicketItem::IN_PROGRESS){
					$result .= "<td><a class=\"$textClass\" href=\"javascript:waitForParaClinicService($id);\">".L10nHelper::_("Test")."</a></td>";
				} else {
					$result .= "<td>&nbsp;</td>";
				}
				$result .= "<td><a class=\"$textClass\" href=\"javascript:completeTicketItem($id);\">".L10nHelper::_("Finish")."</a></td>";
			}
		}
		$result .= "</tr>";
		return $result;
	}

	private static function buildPackageItem($data, $fields, $showLink=false) {
		$order = $data['item_order'];
		$id = $data['package_item_id'];

		$renderAll = (sizeof($fields) == 0) ? TRUE : FALSE;

		$result = "<tr id=\"$id\" >";
		$result .= "<td><span class=\"order\">" . $data['item_order'] . "</span></td>";
		if ($renderAll || in_array('service_name', $fields)) {

			if ($showLink && $data['item_type'] == PackageItem::TEST_TYPE) {
				$result .= "<td><a href=\"javascript:testDetail($id);\" title=\"".L10nHelper::_("Test detail")."\">" . $data['service_name'] . "</a></td>";
			} else{
				$result .= "<td>" . $data['service_name'] . "</td>";
			}
		}
		if ($renderAll || in_array('room_name', $fields)) {
			$result .= "<td>" . $data['room_name'] . "</td>";
		}
		if ($renderAll || in_array('price', $fields)) {
			$result .= "<td>" . L10nHelper::renderCurrency($data['price']) . "</td>";
		}

		if ($renderAll || in_array('payment_type', $fields)) {
			if ($data['payment_type'] == Service::AFTER) {
				$temp = L10nHelper::_("Postpaid");
			} else if ($data['payment_type'] == Service::BEFORE) {
				$temp = L10nHelper::_("Prepaid");
			}
			$result .= "<td>" . $temp . "</td>";
		}

		if ($renderAll || in_array('cancel_button', $fields)) {
			$result .= "<td>"
				. "<a href=\"javascript:deletePackageItem($id);\" title=\"".L10nHelper::_("Delete service")."\"><img src=\"../images/remove_small.png\"</a> </td>";
		}
		$result .= "</tr>";
		return $result;
	}


	private static function determineClassCSS($status) {
		$class = "elementDisabled";
		$delClass = "elementDisabled";

		// Nguyen comment on Mar 16, 2009
		// Allowance to delete ticket item in all status
		$delClass = "elementEnable";
		if ($status == TicketItem::IN_PROGRESS || $status == TicketItem::WAITING ){
			$class = "elementEnable";
		}
		/*
		if ($status == TicketItem::OPEN) {
			$delClass = "elementEnable";
		} else if ($status == TicketItem::IN_PROGRESS ||
				$status == TicketItem::WAITING ){
			$class = "elementEnable";
		}
		*/
		return array('textClass' => $class, 'delClass' => $delClass);
	}

	//TODO: need to improve
	// 1. Delete test item in this test
	// 2. Better HTML, 2 columns
	private static function buildHTMLTest($testName, $data) {
		$mod = sizeof($data) % 2;
		$div = floor(sizeof($data) / 2);
		$row = ($mod > 0)?$div+1:$div;

		$html = "";
		$html .= "<p>$testName</p>";
		$html .= "<table><tr><td><ol>";

		for ($i=0; $i < $row; $i++) {
			$html .= "<li>" . $data[$i]['name'] . "</li>";
		}
		$html .= "</ol></td>";
		$html .= "<td align=\"top\">";
		$start = $row + 1;
		$html .= "<ol start=\"$start\">";
		for ($i=$row; $i < sizeof($data); $i++) {
			$html .= "<li>". $data[$i]['name'] ."</li>";
		}

		$html .= "</ol></td></tr></table>";
		return $html;
	}

	private static function buildHTMLCompositeService($compositeId, $data) {
		$size = sizeof($data);
		$different = ($size % 2 > 0)?($size + 1)/2:$size/2;

		$html = "";
		$html .= "<input id=\"composite_service_id\" type=\"hidden\" value=\"$compositeId\">";
		$html .= "<table id=\"composite_service_item_data\" class=\"details_noalign\" cellspacing=\"0\" cellpaddding=\"0\">";

		for ($i = 0; $i < $different; $i = $i + 1) {
			$html .= "<tr>";
			$html .= self::addTD($data, $i);
			if ($i + $different < $size) {
				$html .= self::addTD($data, $i+$different);
			}
			$html .= "</tr>";
		}
		$html .= "</table>";
		return $html;
	}

	private function addTD($data, $i) {
		$serviceId = $data[$i]['service_id'];
		$name = $data[$i]['name'];
		$disabled = ($data[$i]['optional'] == "no")?" disabled ":" ";
		$selected = ($data[$i]['selected'] == "yes")?" checked ":" ";
		$price = $data[$i]['price'];

		$html = "<td><input style=\"padding-left: 30px;\" class=\"composite_service_item_popup\" ".$disabled.$selected." id=\"$serviceId\" type=\"checkbox\" value=\"$serviceId\"></td>";
		$html .= "<td style=\"width: 200px;\" class=\"label\"><label for=\"$serviceId\">$name</label></td>";
		$html .= "<td style=\"width: 120px; padding-right: 20px;\"align=\"right\">".L10nHelper::renderCurrency($price)." ".L10nHelper::_("VND")."</td>";

		return $html;
	}

	public static function getTicketItemStatus($status) {
		switch ($status) {
			case TicketItem::OPEN:
				return L10nHelper::_("Waiting examination");
			case TicketItem::IN_PROGRESS:
				return L10nHelper::_("Examining");
			case TicketItem::WAITING:
				return L10nHelper::_("Waiting for testing result");
			case TicketItem::CLOSED:
				return L10nHelper::_("Close_1");
			default:
				return "";
		}

	}
}
?>
